import $api from "../../api"

export default {
    namespaced: true,
    state: {
        slideshowList:[],
    },
    mutations: {
        changeList(state,payload){
            state.slideshowList.splice(0,state.slideshowList.length);
            console.log(state.slideshowList);
            state.slideshowList.push(payload);
            console.log(state.slideshowList);
        }
    },
    actions: {
        // 获取所有轮播图
        async sildeshow(context, payload) {
            // console.log("轮播图模块");
            let res = await $api.sildeshowApi.getAllSwiper();
            console.log(res.data.message);
            context.state.slideshowList=res.data.message
        },
        // 轮播图文件上传
        async fileUploadSildeShow(context,payload){
            let res = await $api.sildeshowApi.getfileUpload(payload);
            console.log("轮播图文件上传");
            console.log(res);
        },
        // 轮播图删除上传文件
        async delSildeShow(context,payload){
            let res = await $api.sildeshowApi.getdeleteFiles(payload);
            console.log("轮播图删除上传文件");
            console.log(res);
        },
        // 添加轮播图
        async addSwiper(context,payload){
            let res = await $api.sildeshowApi.getaddSwiper(payload);
            console.log("轮播图文件上传");
            console.log(res);
            context.dispatch("sildeshow")
        },
        // 轮播图上下架
        async upORdown(context,payload){
            let res = await $api.sildeshowApi.getupdateSwiperShow(payload);
            console.log("轮播图上下架");
            console.log(res);
            // context.dispatch("sildeshow");
        },
        // 删除轮播图
        async deleteImg(context,payload){
            let res = await $api.sildeshowApi.getdeleteSwiper(payload);
            console.log("轮播图删除");
            console.log(res);
            context.dispatch("sildeshow");
        },
        // 修改轮播图
        async updateSwiper(context,payload){
            console.log("修改轮播图");
            let res = await $api.sildeshowApi.getupdateSwiper(payload);
            // console.log(res.data);
            // if(res.data.msg){
                context.dispatch("sildeshow")
            // }
            return res.data
        },
        // 根据编号查询轮播图
        async getSearch(context,payload){
            // console.log("根据编号查询轮播图");
            let res = await $api.sildeshowApi.getfindById(payload);
            context.commit("changeList",res.data.data)
            // console.log(res.data.data);
        }

    }
}